<?php

/*
 *   Copyright (c) 2012—2017 成都零点信息技术有限公司 All
 */

/**
 * 创建快跑者配送订单
 *
 * @author xuhaha sxuhaha@gmail.com
 */

header('Content-type: text/html; charset=utf-8');

// 引用 KeloopSDK 文件
require '../../KeloopSdk.php';

// 获取配置
$config = include_once '../config.php';

try {
    $orderId = time();  // 生成一个第三方订单 ID
    $preTime = time() + 3600;   // 预计一个小时之后送达
    // 封装参数
    $param = [
        'shop_id' => 1,
        'shop_name' => '一家餐馆',
        'shop_tel' => '18215675751',
        'shop_address' => '成都市金牛区金卉院',
        'shop_tag' => '104.181909,30.679741',

        'order_content' => '2份烧白开(100x1),2份拉面(18x1)',
        'order_note' => '不要太辣了',
        'order_mark' => '12',
        'order_from' => '美团外卖',
        'order_time' => '2016-12-31 23:59:59',
        'order_photo' => 'http://a4.att.hudong.com/38/47/19300001391844134804474917734_950.png',
        'note' => $orderId,

        'customer_name' => '张三丰',
        'customer_tel' => '18288888888',
        'customer_address' => '成都市金牛区蓝海天地1栋421',
        'customer_tag' => '104.081909,30.779741',

        'order_no' => $orderId,
        'order_price' => 99.99,
        'order_origin_price' => 100.00,
        'pay_status' => 1,
        'pay_fee' => 1.66,
        'pre_times' => $preTime
    ];
    // 创建 SDK 实例
    $sdk = new KeloopSdk($config);
    // 调用 createOrder 方法
    $result = $sdk->createOrder($param);
    var_dump($result);
    // 业务逻辑处理
    if (is_null($result)) {
        exit('创建订单失败');
    } else if (is_array($result)) {
        if ($result['code'] == 200) {
            exit('success');
        } else {
            exit('错误信息：' . $result['message']);
        }
    } else {
        exit('接口调用异常');
    }
} catch (Exception $e) {
    exit('接口调用异常：' . $e->getMessage());
}
